package com.aaa.stock.service.impl;

import com.aaa.entity.StockInventoryLog;
import com.aaa.entity.StockPurchaseItem;
import com.aaa.stock.dao.InventoryDao;
import com.aaa.stock.service.InventoryService;
import com.aaa.stock.vo.InvetoryVo;
import com.aaa.vo.Result;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.List;
import java.util.Objects;

@Service
public class InventoryServiceImpl extends ServiceImpl<InventoryDao, StockInventoryLog> implements InventoryService  {
    @Autowired
    private InventoryDao inventoryDao;
    //查询
    @Override
    public Result<IPage<StockInventoryLog>> getByPage(Integer currentPage, Integer pageSize, InvetoryVo invetoryVo) {

        IPage<StockInventoryLog> page=new Page<>(currentPage,pageSize);
        QueryWrapper<StockInventoryLog> wrapper=new QueryWrapper<>();
        if(StringUtils.hasText(invetoryVo.getPurchaseId())){
            wrapper.eq("purchase_id",invetoryVo.getPurchaseId());
        }
        if (StringUtils.hasText(invetoryVo.getMedicinesName())){
            wrapper.like("medicines_name",invetoryVo.getMedicinesName());
        }
        if (Objects.nonNull(invetoryVo.getMedicinesType())){
            wrapper.eq("medicines_type",invetoryVo.getMedicinesType());
        }
        if (Objects.nonNull(invetoryVo.getProducterId())){
            wrapper.eq("producter_id",invetoryVo.getProducterId());
        }
        if (Objects.nonNull(invetoryVo.getPrescriptionType())){
            wrapper.eq("prescription_type",invetoryVo.getPrescriptionType());
        }
        if(Objects.nonNull(invetoryVo.getDateRange())&&invetoryVo.getDateRange().length==2){
            wrapper.between("create_time",invetoryVo.getDateRange()[0],invetoryVo.getDateRange()[1]);
        }
        IPage<StockInventoryLog>page1=inventoryDao.selectPage(page,wrapper);
        return new Result<>(2000,"查询",page1);
    }




}
